package com.gaofei.job;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Component
public class MyTask {
    @XxlJob("myJobHandler")
    public void aa(){
        String gao = "1992-08-24";
        String bao = "1998-08-25";
        String yu = "2000-08-26";
        Date gaoday = DateUtil.parse(gao);
        Date baoday = DateUtil.parse(bao);
        Date yuday = DateUtil.parse(yu);

        //每天早上8点,查询当天过生日的用户,并邮寄提醒
        User u1 = new User(1, "zhangsan1", gaoday, "79527743@qq.com");
        User u2 = new User(2, "zhangsan2", baoday, "3505127399@qq.com");
        User u3 = new User(3, "zhangsan3", yuday, "2825055204@qq.com");
        //模拟数据库查询出来的用户数据  作业: 查询生日月份和天数与今天一样的用户sql
        List<User> users = Arrays.asList(u1, u2, u3);
        //你得从数据库中筛选出来
        int month = DateUtil.month(new Date());
        int day = DateUtil.dayOfMonth(new Date());

        System.out.println(month+"======="+day);//7=======25

        //jdk 1.8的特性  stream流的过滤
        List<User> collect = users.stream().filter(user -> {if (DateUtil.month(user.getBirthday()) == month && DateUtil.dayOfMonth(user.getBirthday()) == day) {return true;}return false;}).collect(Collectors.toList());

        System.out.println(collect);


        //遍历集合,筛选条件
        /*for (User user : users) {
            if(DateUtil.month(user.getBirthday())==month&&DateUtil.dayOfMonth(user.getBirthday())==day ){
                System.out.println(user.getMail());
                //发邮件操作
            }
        }
*/
    }
}
